//
//  ShowMsgBox.m
//  iMessage
//
//  Created by kare on 14-3-7.
//  Copyright (c) 2014年 kare. All rights reserved.
//

#import "ShowMsgBox.h"


@implementation ShowMsgBox

@end

#define SHOWTSGMSG 101010011

void showView(NSString *str)
{
    UIFont *font = [UIFont systemFontOfSize:18.0f];
    CGSize textSize = [str sizeWithFont:font constrainedToSize:CGSizeMake(280, 60)];
	
	UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, textSize.width + 25, textSize.height + 20)];
	label.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
    label.textAlignment = UITextAlignmentCenter;
	label.font = font;
	label.text = str;
	label.numberOfLines = 0;
    label.layer.cornerRadius = 5;
//    label.tag = SHOWTSGMSG;
    label.textColor = [UIColor whiteColor];
    
    UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
	
	CGPoint point = CGPointMake(window.frame.size.width/2, window.frame.size.height/2 + 100);
    
    label.center = point;
    
    window.backgroundColor = [UIColor clearColor];
    
    [UIView animateWithDuration:0.9f animations:^{
        [window addSubview:label];
        label.alpha = 1.0f;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3f delay:3.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
            label.alpha = 0.0f;
        } completion:^(BOOL finished) {
            [label removeFromSuperview];
        }];
    }];
}


void showViewInView(UIView*view , NSString *strMsg)
{
    UIFont *font = [UIFont systemFontOfSize:18.0f];
    CGSize textSize = [strMsg sizeWithFont:font constrainedToSize:CGSizeMake(280, 60)];
	
	UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, textSize.width + 25, textSize.height + 20)];
	label.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
    label.textColor = [UIColor whiteColor];
    label.textAlignment = UITextAlignmentCenter;
	label.font = font;
	label.text = strMsg;
	label.numberOfLines = 0;
    label.layer.cornerRadius = 5;
    label.tag = SHOWTSGMSG;
    
    CGPoint centerPoint = view.center;
    centerPoint.y += 100;
    label.center = centerPoint;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:0.9f animations:^{
            [view addSubview:label];
            label.alpha = 1.0f;
        } completion:^(BOOL finished) {
//            [UIView animateWithDuration:0.3f delay:3.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
//                label.alpha = 0.0f;
//            } completion:^(BOOL finished) {
//                [label removeFromSuperview];
//            }];
        }];
    });
    
}

void hideViewInView(UIView*tempView)
{
    dispatch_async(dispatch_get_main_queue(), ^{
        UIView *view = [tempView viewWithTag:SHOWTSGMSG];
        if (view)
        {
            [UIView animateWithDuration:0.3f delay:.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                view.alpha = 0.0f;
            } completion:^(BOOL finished) {
                [view removeFromSuperview];
            }];
        }
    });
}

